<?php

namespace App\Transformers\Order;

use App\Models\Order;
use App\Transformers\User\UserTransformer;
use League\Fractal\TransformerAbstract;

class OrderCashTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['user'];

    public function transform(Order $data)
    {
        return [
            'id' => $data->id,
            'user_id' => $data->user_id ?? '',
            'order_number' => $data->order_number ?? '',
            'pay_price' => $data->pay_price ?? '',
            'deduction_price' => $data->deduction_price ?? '',
            'pay_time' => $data->pay_time ?? '',
            'user' => $data->user ?? '',
            'deleted_at' => $data->deleted_at ? $data->deleted_at->format("Y-m-d H:i:s") : '',
            'created_at' => $data->created_at ? $data->created_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $data->updated_at ? $data->updated_at->format("Y-m-d H:i:s") : '',
        ];
    }

    /**
     * 订单用户信息
     */
    public function includeUser(Order $order)
    {
        return $this->item($order->user,new UserTransformer());
    }
}
